import request from "@/utils/request";
import { generateMD5Validate } from "@/utils/common";
const FILES_BASE_URL = "/api/v1";
const CommonAPI = {
  /**
   * 发送验证码
   * @param {Object} data - 请求参数
   * @returns {Promise} - 返回发送验证码
   */
  captchaSmse(data: { phone: string }) {
    return request({
      url: `${FILES_BASE_URL}/auth/smsCaptcha`,
      method: "get",
      params: data,
    });
  },
  // 获取品牌
  getBrandList(data: { keyword: string }) {
    return request({
      url: `${FILES_BASE_URL}/common/brand`,
      method: "get",
      params: data,
    });
  },
  // 获取材料分类
  getMaterialCategory(params: MaterialCategoryForm) {
    return request({
      url: `${FILES_BASE_URL}/common/materialCategory`,
      method: "get",
      params,
    });
  },
  /**
   * 获取全部的分类（是否包含叶子结点）
   * @param params
   */
  getAllMaterialCategory(params: AllMaterialCategoryForm) {
    return request({
      url: `${FILES_BASE_URL}/common/allMaterialCategory`,
      method: "get",
      params,
    });
  },
  // 获取地区
  getArea(parentCode: string) {
    return request({
      url: `${FILES_BASE_URL}/basicData/getRegionList`,
      method: "get",
      params: { parentCode },
    });
  },
  /**
   * 获取品牌
   * @param params
   */
  getBrand(params: BrandForm) {
    return request({
      url: `${FILES_BASE_URL}/common/brand`,
      method: "get",
      params,
    });
  },
  /**
   * 获取分类
   */
  getCategoryInfo(id: number) {
    return request({
      url: `${FILES_BASE_URL}/requirement/category/list?parentId=${id}`,
      method: "get",
    });
  },
  /**
   * 通过id获取品牌
   */

  getBycategoryId(data: any) {
    return request({
      url: "/api/v1/requirement/brand/listByCategoryIds",
      method: "post",
      data,
    });
  },
};

// 获取身份证背面信息
export function getIdCardBackInfo(params: any) {
  const { OCR_TIME, OCR_UUID, OCR_SECRET } = generateMD5Validate();
  return request({
    headers: {
      ocrTime: OCR_TIME,
      ocrUuid: OCR_UUID,
      ocrSecret: OCR_SECRET,
    },
    url: `${FILES_BASE_URL}/ocr/getIdCardBackInfo`,
    method: "get",
    params: params,
  });
}

// 获取身份证正面信息
export function getIdCardFaceInfo(params: any) {
  const { OCR_TIME, OCR_UUID, OCR_SECRET } = generateMD5Validate();

  return request({
    headers: {
      ocrTime: OCR_TIME,
      ocrUuid: OCR_UUID,
      ocrSecret: OCR_SECRET,
    },
    url: `${FILES_BASE_URL}/ocr/getIdCardFaceInfo`,
    method: "get",
    params: params,
  });
}
// 获取营业执照信息
export function getBusinessLicenseInfo(params: any) {
  return request({
    url: `${FILES_BASE_URL}/ocr/getBusinessLicenseInfo`,
    method: "get",
    params: params,
  });
}
/**
 * 材料品类分页列表，顶级parentCode传零
 */
export interface MaterialCategoryForm {
  parentCode: string;
}

export interface AllMaterialCategoryForm {
  isLeaf: boolean;
}

export interface BrandForm {
  /*关键字*/
  keyword: string;
}
export default CommonAPI;
